#!/bin/bash

DIR="$HOME/.pyenv"
echo "$DIR"

# git-clone-update $dir $git-repo
function git-clone-update(){
  if [ -d "$1" ]; then
    cd "$1" && git remote -v && git-reset-url $2 && git pull
  else
    git clone $2 $1
  fi
}

function git-reset-url(){
  git remote set-url origin $1
}

sudo apt-get update
sudo apt-get install git curl -y
sudo apt-get install build-essential python-dev python-setuptools python-pip python-smbus curl -y
sudo apt-get install libncursesw5-dev libgdbm-dev libc6-dev -y
sudo apt-get install zlib1g-dev libsqlite3-dev tk-dev -y
sudo apt-get install libssl-dev openssl -y
sudo apt-get install libffi-dev -y

git-clone-update "$DIR" "https://gitee.com/mirrors/pyenv.git"
git-clone-update "$DIR/plugins/pyenv-doctor" "https://gitee.com/azhao-1981/pyenv-doctor"
git-clone-update "$DIR/plugins/pyenv-installer" "https://gitee.com/azhao-1981/pyenv-installer"
git-clone-update "$DIR/plugins/pyenv-update" "https://gitee.com/azhao-1981/pyenv-update"
git-clone-update "$DIR/plugins/pyenv-virtualenv" "https://gitee.com/azhao-1981/pyenv-virtualenv"
git-clone-update "$DIR/plugins/pyenv-which-ext" "https://gitee.com/azhao-1981/pyenv-which-ext"

echo '
export PATH="~/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
export  PYTHON_BUILD_MIRROR_URL="http://pyenv.qiniudn.com/pythons/"
' >> ~/.bashrc

